package com.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

//用来获取spring创建好的工厂
@Component
public class AppUtils implements ApplicationContextAware {
    //保留下来的工厂
    private static ApplicationContext context;

    //将创建好的工厂以参数的形式传递给这个类
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        AppUtils.context = applicationContext;
    }

    //在工厂中获取bean
    public static Object getBeanByName(String beanName){
        return AppUtils.context.getBean(beanName);
    }
}
